package cn.mugutu.finance.dto;

import cn.mugutu.finance.domain.system.Menu;
import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class MenuDto {

    private Long id;
    private String name;
    private String uri;
    private String icon;
    private String parentName;
    private Long parentId;


    public MenuDto(Menu menu) {
        super();
        this.id = menu.getId();
        this.name = menu.getName();
        this.uri = menu.getUrl();
        this.icon = menu.getIcon();
        this.parentName = menu.getParent() != null ? menu.getParent().getName() : "/";
        this.parentId = menu.getParent() != null ? menu.getParent().getId() : 1L;
    }

    /**
     * 将List<Menu> 转化为List<MenuDto>
     *
     * @param list
     * @return
     */
    public static List<MenuDto> menuListToMenuDtoList(List<Menu> list) {
        List<MenuDto> dtoList = new ArrayList<>();
        for (Menu menu : list) {
            MenuDto dto = new MenuDto(menu);
            dtoList.add(dto);
        }
        return dtoList;
    }


}
